/*

	File-Name: 5-analysis-plus-bjps.do
	Last Updated: 4/5/22
	Author: Jessica Gottlieb
	Purpose: Analyses for BJPS submission
	
*/

* To save figures and tables
cd Figures

* Save as macro
global controls "i.market_size i.rent_dummy i.yoruba i.trust i.lirs_connect i.friends_market i.club"

**Measuring the moderator
*Tax collection by each agent
generate lirsfee=0
replace lirsfee=1 if q42_b==4
replace lirsfee=1 if q44_b==4

generate localfee=0
replace localfee=1 if q42_b==3
replace localfee=1 if q44_b==3

*For LIRS, this would take the form of any past visit or collection of tax. 
gen lirs_enforce=0
replace lirs_enforce=1 if visit_lirs==1 | lirsfee==1
*For the marketplace association, any past collection of tax or reported reliance on the association to adjudicate disputes 
gen mpa_enforce=0
replace mpa_enforce=1 if mpafee==1 | mpasolve==1


* Generate main results

// Fig 2

*update betterbar to remove dv from labels
do "../6 - betterbar-rev.do"

betterbarci etcc2 if treatment!=1 & etcc2!=., by(treatment) n barlab pct barcolor(gs10)
graph export "etcc_means.pdf", as(pdf) replace

generate etcc20y=etcc2 if yoruba==0
label var etcc20y "Non-Yoruba"
generate etcc21y=etcc2 if yoruba==1
label var etcc21y Yoruba

generate etcc20t=etcc2 if trust2==0
label var etcc20t "Trust MPA More"
generate etcc21t=etcc2 if trust2==1
label var etcc21t "Trust LIRS Weakly More"

generate etcc20s=etcc2 if service_access_d_b==0
label var etcc20s "Below-median Access to Services"
generate etcc21s=etcc2 if service_access_d_b==1
label var etcc21s "Above-median Access to Services"

generate etcc20l=etcc2 if lirs_enforce==0
label var etcc20l "No Prior Contact w/LIRS"
generate etcc21l=etcc2 if lirs_enforce==1
label var etcc21l "Prior Contact with LIRS"

generate etcc20m=etcc2 if mpa_enforce==0
label var etcc20m "No Prior Contact w/MPA"
generate etcc21m=etcc2 if mpa_enforce==1
label var etcc21m "Prior Contact with MPA"


betterbarci etcc20y etcc21y etcc20t etcc21t etcc20s etcc21s etcc20l etcc21l etcc20m etcc21m if treatment!=1 & etcc2!=., n barlab pct barcolor(gs10)
graph export "etcc_means_mods.pdf", as(pdf) replace


// Fig 3
reg etcc2 i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
local c: di %4.3f _b[1.T_messenger#1.trust2]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_messenger) at(trust2=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Trust MPA more" 1 "Trust LIRS weakly more", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("MPA Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(mpa, replace)
	
reg etcc2 i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
local c: di %4.3f _b[2.T_messenger#1.trust2]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_messenger) at(trust2=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Trust MPA more" 1 "Trust LIRS weakly more", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("LIRS Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(lirs, replace)

gr combine mpa lirs, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI", pos(12))
graph export "etcc2ByTrustmargins_trust2.pdf", as(pdf) replace


// Fig 4 

reg etcc2 i.T_message##i.service_access_d_b $controls , r
local c: di %4.3f _b[1.T_message#1.service_access_d_b]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_message) at(service_access_d_b=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Below-median" 1 "Above-Median", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Enforcement Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(enforcement, replace)

reg etcc2 i.T_message##i.service_access_d_b $controls , r
local c: di %4.3f _b[2.T_message#1.service_access_d_b]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_message) at(service_access_d_b=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Below-median" 1 "Above-Median", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Public Goods Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(pg, replace)

gr combine pg enforcement, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI", pos(12)) b1title("Access to Services", pos(6) size(small) ring(0)) 
graph export "service_etcc2_message_mfx.pdf", replace

// Fig 5

reg etcc2 i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
local c: di %4.3f _b[1.T_message#1.lirs_enforce]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_message) at(lirs_enforce=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "No Contact w/ LIRS" 1 "Contact w/ LIRS", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Enforcement Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(enforcement, replace)

reg etcc2 i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
local c: di %4.3f _b[2.T_message#1.lirs_enforce]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_message) at(lirs_enforce=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "No Contact w/ LIRS" 1 "Contact w/ LIRS", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Public Goods Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(pg, replace)

gr combine pg enforcement, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI when LIRS Delivered Message", pos(12)) 
graph export "contactlirs_etcc2_message_mfx.pdf", as(pdf) replace

reg etcc2 i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
local c: di %4.3f _b[1.T_message#1.mpa_enforce]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_message) at(mpa_enforce=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "No Contact w/ MPA" 1 "Contact w/ MPA", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Enforcement Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(enforcement, replace)

reg etcc2 i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
local c: di %4.3f _b[2.T_message#1.mpa_enforce]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_message) at(mpa_enforce=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "No Contact w/ MPA" 1 "Contact w/ MPA", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Public Goods Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(pg, replace)

gr combine pg enforcement, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI when MPA Delivered Message", pos(12)) 
graph export "contactmpa_etcc2_message_mfx.pdf", as(pdf) replace

// Fig 6

reg etcc2 i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
local c: di %4.3f _b[1.T_messenger#1.yoruba]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_messenger) at(yoruba=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Non-Yoruba" 1 "Yoruba", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("MPA Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(mpa, replace)

reg etcc2 i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
local c: di %4.3f _b[2.T_messenger#1.yoruba]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_messenger) at(yoruba=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Non-Yoruba" 1 "Yoruba", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("LIRS Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(lirs, replace)

gr combine mpa lirs, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI", pos(12))
graph export "etcc2ByYorubamargins2.pdf", as(pdf) replace

reg etcc2 i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
local c: di %4.3f _b[1.T_message#1.yoruba]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_message) at(yoruba=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Non-Yoruba" 1 "Yoruba", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Enforcement Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(mpa, replace)

reg etcc2 i.i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
local c: di %4.3f _b[2.T_message#1.yoruba]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_message) at(yoruba=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Non-Yoruba" 1 "Yoruba", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Public Goods Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(lirs, replace)

gr combine mpa lirs, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI", pos(12))
graph export "etcc2ByYorubamargins3.pdf", as(pdf) replace

// Appendices

// Table 1

label var lirs_enforce "Prior Contact w/ LIRS"
label var mpa_enforce "Prior Contact w/ MPA"

reg etcc2 i.T_messenger $controls , r
est store m0

reg etcc2 i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
est store m1

reg etcc2 i.T_message##i.service_access_d_b $controls , r
est store m2

reg etcc2 i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
est store m6

reg etcc2 i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
est store m7

reg etcc2 i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m3

reg etcc2 i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m4

reg etcc2 T_messenger##c.mpaquality $controls , cluster(mname_b)
est store m5

esttab m0 m1 m2 m6 m7 m3 m4 /// 
	using "diffeffects_new.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) label booktabs  replace ///
	stats(N, labels("Observations") f(0))  ///
	title("Effect of Tax Appeals on e-TCC Registration \label{tab:diffeffects}")  ///
	varlabels (_cons Constant) ///
	drop(*.market_size *.rent_dummy *.trust *.lirs_connect *.friends_market *.club ) ///
	nonotes  nobaselevels  nogaps mtitles("\shortstack{Effect of\\Messenger Treatment}" "\shortstack{Relative Trust\\in Messenger}" "\shortstack{Message Credibility\\through Service Access}" "\shortstack{Message Credibility\\through LIRS Contact}" "\shortstack{Message Credibility\\through MPA Contact}" "\shortstack{Message Treatment\\by Ethnicity}" "\shortstack{Messenger Treatment\\by Ethnicity}") ///
	addnote("OLS model with robust standard errors, blocking variables included as controls. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.8\textwidth, totalheight=0.5\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	

// Table 2, no controls to check for contamination bias 

reg etcc2 i.T_messenger  , r
est store m0

reg etcc2 i.T_messenger##i.trust2 , robust
est store m1

reg etcc2 i.T_message##i.service_access_d_b  , r
est store m2

reg etcc2 i.T_message##i.lirs_enforce , r
est store m6

reg etcc2 i.T_message##i.mpa_enforce  if T_messenger!=2, r
est store m7

reg etcc2 i.T_messenger##i.yoruba , robust
est store m3

reg etcc2 i.T_message##i.yoruba , robust
est store m4

reg etcc2 T_messenger##c.mpaquality , cluster(mname_b)
est store m5

esttab m0 m1 m2 m6 m7 m3 m4 /// 
	using "diffeffects_nocontrols.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) label booktabs  replace ///
	stats(N, labels("Observations") f(0))  ///
	title("Replicating Table \ref{tab:diffeffects} without Controls \label{tab:diffeffectsnocontrols}")  ///
	varlabels (_cons Constant) ///
	nonotes  nobaselevels  nogaps mtitles("\shortstack{Effect of\\Messenger Treatment}" "\shortstack{Relative Trust\\in Messenger}" "\shortstack{Message Credibility\\through Service Access}" "\shortstack{Message Credibility\\through LIRS Contact}" "\shortstack{Message Credibility\\through MPA Contact}" "\shortstack{Message Treatment\\by Ethnicity}" "\shortstack{Messenger Treatment\\by Ethnicity}") ///
	addnote("OLS model with robust standard errors, blocking variables included as controls. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.8\textwidth, totalheight=0.5\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	

// Table 3, with outcome that includes payment of tax or etcc2

gen compliance=compliance3
*replace compliance=0 if q45_year_pay_income<2018
tab etcc2 compliance
replace compliance=1 if etcc2==1

reg compliance i.T_messenger $controls , r
est store m0

reg compliance i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
est store m1

reg compliance i.T_message##i.service_access_d_b $controls , r
est store m2

reg compliance i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
est store m6

reg compliance i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
est store m7

reg compliance i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m3

reg compliance i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m4

reg compliance T_messenger##c.mpaquality $controls , cluster(mname_b)
est store m5

esttab m0 m1 m2 m6 m7 m3 m4 /// 
	using "diffeffects_compliance.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) label booktabs  replace ///
	stats(N, labels("Observations") f(0))  ///
	title("Effect of Tax Appeals on e-TCC Registration or Tax Payment \label{tab:diffeffectscompliance}")  ///
	varlabels (_cons Constant) ///
	drop(*.market_size *.rent_dummy *.trust *.lirs_connect *.friends_market *.club ) ///
	nonotes  nobaselevels  nogaps mtitles("\shortstack{Effect of\\Messenger Treatment}" "\shortstack{Relative Trust\\in Messenger}" "\shortstack{Message Credibility\\through Service Access}" "\shortstack{Message Credibility\\through LIRS Contact}" "\shortstack{Message Credibility\\through MPA Contact}" "\shortstack{Message Treatment\\by Ethnicity}" "\shortstack{Messenger Treatment\\by Ethnicity}") ///
	addnote("OLS model with robust standard errors, blocking variables included as controls. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.8\textwidth, totalheight=0.5\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	

// Table 4, with outcome of tax morale

reg tax_morale2_e i.T_messenger $controls , r
est store m0

reg tax_morale2_e i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
est store m1

reg tax_morale2_e i.T_message##i.service_access_d_b $controls , r
est store m2

reg tax_morale2_e i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
est store m6

reg tax_morale2_e i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
est store m7

reg tax_morale2_e i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m3

reg tax_morale2_e i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club , robust
est store m4

reg tax_morale2_e T_messenger##c.mpaquality $controls , cluster(mname_b)
est store m5

esttab m0 m1 m2 m6 m7 m3 m4 /// 
	using "diffeffects_morale.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) label booktabs  replace ///
	stats(N, labels("Observations") f(0))  ///
	title("Effect of Tax Appeals on Tax Morale \label{tab:diffeffectsmorale}")  ///
	varlabels (_cons Constant) ///
	drop(*.market_size *.rent_dummy *.trust *.lirs_connect *.friends_market *.club ) ///
	nonotes  nobaselevels  nogaps mtitles("\shortstack{Effect of\\Messenger Treatment}" "\shortstack{Relative Trust\\in Messenger}" "\shortstack{Message Credibility\\through Service Access}" "\shortstack{Message Credibility\\through LIRS Contact}" "\shortstack{Message Credibility\\through MPA Contact}" "\shortstack{Message Treatment\\by Ethnicity}" "\shortstack{Messenger Treatment\\by Ethnicity}") ///
	addnote("OLS model with robust standard errors, blocking variables included as controls. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.8\textwidth, totalheight=0.5\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	

// Fig 7 

interflex etcc2 T_marketassoc mpaquality lirs_mpaquality T_lirs market_size_2 market_size_3 market_size_4 rent_dummy_1 rent_dummy_2 rent_dummy_3 yoruba trust_1 trust_2 trust_3 lirs_connect friends_market club_1 club_2, cluster(mname_b) ///
	xlabel("MPA Quality Index") ///
	ylabel("e-TCC Registration") ///
	dlabel("MPA Treatment")
graph export "mpaquality_etcc2_MPA.pdf", as(pdf) replace

// Fig 8

reg punish_state_e i.T_messenger##i.service_access_d_b $controls , r
margins, dydx(1.T_messenger) by(service_access_d_b)
marginsplot, yline(0) recast(scatter) ///
	xlabel(, noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("MPA Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	legend(off) name(mpa, replace)

margins, dydx(2.T_messenger) by(service_access_d_b)
marginsplot, yline(0) recast(scatter) ///
	xlabel(, noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("LIRS Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	legend(off) name(lirs, replace)

reg punish_state_e i.T_message##i.service_access_d_b $controls , r
margins, dydx(1.T_message) by(service_access_d_b)
marginsplot, yline(0) recast(scatter) ///
	xlabel(, noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Enforcement Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	legend(off) name(pg, replace)

margins, dydx(2.T_message) by(service_access_d_b)
marginsplot, yline(0) recast(scatter) ///
	xlabel(, noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("Public Goods Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	legend(off) name(enforce, replace)

graph combine mpa lirs pg enforce
graph export "treatment_punishment_byservices.pdf", as(pdf) replace

// Fig 9

reg etcc2 i.T_messenger##i.mpasolve i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
local c: di %4.3f _b[1.T_messenger#1.mpasolve]
matrix table=r(table)
local p= table[4,9]
local p: di %4.3f `p'
margins, dydx(1.T_messenger) at(mpasolve=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Not MPA" 1 "MPA", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("MPA Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	///
	legend(off) name(mpa, replace)
*graph export "etcc2ByTrustmargins_trust2_MPA.pdf", as(pdf) replace
	
reg etcc2 i.T_messenger##i.mpasolve i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club, robust
local c: di %4.3f _b[2.T_messenger#1.mpasolve]
matrix table=r(table)
local p= table[4,11]
local p: di %4.3f `p'
margins, dydx(2.T_messenger) at(mpasolve=(0(1)1))
marginsplot, yline(0) recast(scatter) ///
	xlabel(0 "Not MPA" 1 "MPA", labsize(medium) noticks nogrid) ///
	ylabel(, noticks nogrid) ///
	xtitle("") ///
	ytitle("") ///
	title("LIRS Treatment", size(medlarge)) ///
	xscale(range(-0.25(0.25)1.25)) ///
	note("Interaction term: coefficient = `c', p = `p'", ring(0) position(12) color(gs10) size(medium))	/// 
	legend(off) yscale(off) name(lirs, replace)
*graph export "etcc2ByTrustmargins_trust2_LIRS.pdf", as(pdf) replace

gr combine mpa lirs, ycommon xcommon graphregion(color(white)) rows(1) b2title("Marginal Effects with 95% CI", pos(12)) b1(Who would you approach to solve a problem in the market?)
graph export "etcc2Bympasolve.pdf", as(pdf) replace

// Table 5

gen t1_lirs = 0 if treat_assg == "T1"
replace t1_lirs = 1 if treat_assg == "T2" | treat_assg == "T3"

gen t1_mpa = 0 if treat_assg == "T1"
replace t1_mpa = 1 if treat_assg == "T4" | treat_assg == "T5"

preserve
keep if treat_assg != "C"

balancetable t1_lirs yoruba_b igbo_b hausa_b english_b yorubalang_b pidgin_b hausalang_b q84_b income q1_sex_b age educ rent market_size friends_market club2 tax_morale_b govservice_access_b trustmarketmore trust_lga_b trust_fed_b apc biz_loan visit_lirs using "balancetable_lirsall.tex", observationscolumn ctitles("\shortstack{Formalization\\only}" "\shortstack{LIRS\\Treatment}" "Difference" "Observations") varlabels replace booktabs 

balancetable t1_mpa yoruba_b igbo_b hausa_b english_b yorubalang_b pidgin_b hausalang_b q84_b income q1_sex_b age educ rent market_size friends_market club2 tax_morale_b govservice_access_b trustmarketmore trust_lga_b trust_fed_b apc biz_loan visit_lirs using "balancetable_mpaall.tex", observationscolumn ctitles("\shortstack{Formalization\\only}" "\shortstack{MPA\\Treatment}" "Difference" "Observations") varlabels replace booktabs 
restore

// Table 6

gen int2_compliance = 1 if consent_int2 == "Yes"
replace int2_compliance = 0 if consent_int2 != "Yes" 
replace int2_compliance = . if treat_assg == "T1" | treat_assg == "C"

preserve
keep if treat_assg != "C" | treat_assg != "T1"

balancetable int2_compliance yoruba_b igbo_b hausa_b english_b yorubalang_b pidgin_b hausalang_b q84_b income q1_sex_b age educ using "balancetable_int2compliers1.tex", observationscolumn ctitles("Noncompliers" "Compliers" "Difference" "Observations") varlabels replace booktabs 

balancetable int2_compliance rent market_size friends_market club2 tax_morale_b govservice_access_b trustmarketmore trust_lga_b trust_fed_b apc biz_loan visit_lirs using "balancetable_int2compliers2.tex", observationscolumn ctitles("Noncompliers" "Compliers" "Difference" "Observations") varlabels replace booktabs 
restore

// Table 7
generate attriters = 1 
replace attriters = 0 if consent_e == 1

balancetable attriters yoruba_b igbo_b hausa_b english_b yorubalang_b pidgin_b hausalang_b q84_b income q1_sex_b age educ using "balancetable_attriters1.tex", observationscolumn ctitles("Surveyed" "Attriters" "Difference" "Observations") varlabels replace booktabs 

balancetable attriters rent market_size friends_market club2 tax_morale_b govservice_access_b trustmarketmore trust_lga_b trust_fed_b apc biz_loan visit_lirs using "balancetable_attriters2.tex", observationscolumn ctitles("Surveyed" "Attriters" "Difference" "Observations") varlabels replace booktabs 

// Table 8

label var govservice_access_d_b "Government service access"
label var rent_dummy "Market stall rent"

reg attriters i.T_messenger club2 govservice_access_d_b trust_fed_b q1_sex_b market_size rent_dummy yoruba trust lirs_connect friends_market educ, robust
est store m1

reg attriters i.T_messenger club2 govservice_access_d_b trust_fed_b q1_sex_b market_size educ, robust 
est store m2

reg attriters i.T_messenger##i.club2 govservice_access_d_b trust_fed_b q1_sex_b market_size educ, robust
est store m3

reg attriters i.T_messenger club2 govservice_access_d_b trust_fed_b q1_sex_b market_size  educ income, robust
est store m4

esttab m1 m2 m3 m4 /// 
	using "diffattrit.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) aic(0) label booktabs  replace ///
	stats(N aic, labels("Observations" "AIC") f(0))  ///
	title("Differential Attrition Across Treatment \label{tab:diffattrit}") ///
	varlabels (_cons Constant) ///
	nonotes  nobaselevels  nogaps mtitles("Model 1" "Model 2" "Model 3" "Model 4") ///
	addnote("OLS model with robust standard errors, blocking variables included. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.7\textwidth, totalheight=0.7\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	

// Fig 10
set scheme plotplainblind

reg attriters i.T_messenger##i.club2 govservice_access_d_b trust_fed_b q1_sex_b market_size, robust
margins, by(club2 T_messenger)
marginsplot, recast(scatter) xdimension(club2 T_messenger) horizontal ///
	xtitle("Predicted Attrition") ytitle("") ///
	ylabel(1 "No Tax Appeal" 2 "MPA Treatment" 3 "LIRS Treatment" 3.5 "{bf:NOT A MEMBER}" 4 "No Tax Appeal" 5 "MPA Treatment" 6 "LIRS Treatment" 6.5 "{bf:MEMBER OF CLUB}", noticks nogrid) ///
	yline(3.5 6.5) 
graph export "attritByClubmargins1.pdf", as(pdf) replace 

// Table 9

gen in_endline = 0
replace in_endline = 1 if consent_e == 1

reg in_endline i.T_messenger##i.club2 govservice_access_d_b trust_fed_b q1_sex_b market_size, robust
predict pw, xb 
gen ipw = 1/pw

reg etcc2 i.T_messenger##i.trust2 i.market_size i.rent_dummy i.yoruba i.lirs_connect i.friends_market i.club [pw = ipw], robust
est store m1

reg etcc2 i.T_message##i.service_access_d_b $controls [pw = ipw], r
est store m2

reg etcc2 i.T_messenger##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club [pw = ipw], robust
est store m3

reg etcc2 i.T_message##i.yoruba i.market_size i.rent_dummy i.trust i.lirs_connect i.friends_market i.club [pw = ipw], robust
est store m4

reg etcc2 T_messenger##c.mpaquality $controls [pw = ipw], cluster(mname_b)
est store m5

esttab m1 m2 m3 m4 m5 /// 
	using "diffeffects_ipw_new.tex", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) se b(3) se(3) r2(2) label booktabs  replace ///
	stats(N, labels("Observations") f(0))  ///
	title("Differential Effects of Tax Appeals on e-TCC Registration, with Inverse Probability Weights for Attrition \label{tab:diffeffectsipw}")  ///
	varlabels (_cons Constant) ///
	drop(*.market_size *.rent_dummy *.trust *.lirs_connect *.friends_market *.club ) ///
	nonotes  nobaselevels  nogaps mtitles("\shortstack{Relative Trust\\in Messenger}" "\shortstack{Message Credibility\\through Service Access}" "Ethnicity" "Ethnicity" "\shortstack{Message Credibility\\through MPA Quality}") ///
	addnote("OLS model with robust standard errors, blocking variables included. $^+ p<0.10$, $^{*} p<0.05$, $^{**} p<0.01$, $^{***} p<0.001$") ///
	sub("\begin{tabular}" "\begin{adjustbox}{width=0.8\textwidth, totalheight=0.5\textheight} \begin{tabular}" "\end{tabular}" "\end{tabular} \end{adjustbox}")	
	
// Table 10

gen treatcontrol=0 if T_message==0
replace treatcontrol=1 if T_message==1 | T_message==2

label var treatcontrol "Any Tax Appeal"

reg etcc2 i.treatcontrol $controls, robust
estimates store h2a

reg tax_morale2_e i.treatcontrol $controls, robust 
estimates store h2b

reg punish_new i.T_message $controls , robust 
estimates store h2c

reg benefit_new i.T_message $controls , robust 
estimates store h2d

reg etcc2 i.T_messenger##i.trust2 $controls , robust 
estimates store h2e

reg etcc2 i.T_message##i.service_access_d_b $controls , r
estimates store h2f1

reg etcc2 i.T_message##i.lirs_enforce i.market_size i.rent_dummy i.yoruba i.trust i.friends_market i.club if T_messenger!=1, r
est store h2f2a

reg etcc2 i.T_message##i.mpa_enforce $controls if T_messenger!=2, r
estimates store h2f2b

esttab h2e h2d h2c h2f2a h2b h2a h2f2b h2f1 /// 
	using "theoryfamily2_new.tex", nostar b(3) p(3) r2(2) label booktabs alignment(D{.}{.}{-1}) replace ///
	stats(N,layout("\multicolumn{1}{c}{@}") labels("Observations") f(0))  ///
	title("Theory Family 2 Tests \label{tab:theoryfamily2}")  ///
	varlabels (_cons Constant) drop(*market_size *rent_dummy *yoruba *trust *lirs_connect *friends_market *club) ///
	nonotes  nobaselevels  nogaps nonumbers mtitles(h2e h2fb h2b h2a h2c h2d h2fa h2f1) ///
	sub("\begin{table}[htbp]" "\begin{table}[htbp] \setlength{\tabcolsep}{3pt} " "\bottomrule" "FDR Corrected p Value Threshold & 0.006 & 0.013 & 0.019 & 0.025 & 0.031 & 0.038 & 0.044 & 0.050 \\ \bottomrule") ///
	addnote("OLS model with robust standard errors. Nominal p values instead of standard errors in parentheses.")

	
